package com.athuahua.spzx.controller.system;

import com.athuahua.spzx.dto.system.AssginMenuDto;
import com.athuahua.spzx.service.SysRoleMenuService;
import com.athuahua.spzx.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: huahua
 * @Date: 2024/7/25 0025
 * @Time: 14:00
 * @Description:
 */
@Tag(name = "菜单权限管理接口")
@RestController
@RequestMapping("admin/system/sysRoleMenu")
@Slf4j
public class SysRoleMenuController {
    @Resource
    private SysRoleMenuService sysRoleMenuService;


    //1 查询所有菜单 查询角色分配过的菜单id列表
    // findSysRoleMenuByRoleId/41
    @GetMapping("findSysRoleMenuByRoleId/{roleId}")
    @Operation(summary = "查询当前角色分配菜单列表和菜单列表")
    public Result findSysRoleMenuByRoleId(@PathVariable("roleId") Long roleId) {
        log.info("查询角色分配过的菜单id列表 {}", roleId);
        Map<String, Object> map = sysRoleMenuService.findSysRoleMenuByRoleId(roleId);

        return Result.success(map);

    }

    //doAssign
    @PostMapping("doAssign")
    @Operation(summary = "保存分配角色菜单")
    public Result doAssign(@RequestBody AssginMenuDto assginMenuDto) {
        log.info("分配角色菜单 {}", assginMenuDto);
        sysRoleMenuService.doAssign(assginMenuDto);
        return Result.success();
    }
}
